<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>迭代</title>
    <style>
        .wrapper {
            border: 1px solid blue;
            margin: 15px auto;
        }
        .title {
            color: blue;
            font-weight: bold;
        }
        table {
            width: 100%;
        }
        td {
            text-align: center;
        }
    </style>
</head>
<body>

    <div class="wrapper">
        <p class="title">遍历数组</p>
        <c:if test="${ not empty names }">
            <table>
                <tr>
                    <th>index</th>
                    <th>count</th>
                    <th>var</th>
                    <th>is first</th>
                    <th>is last</th>
                    <th>current</th>
                </tr>
            <c:forEach items="${ names }" var="name" varStatus="x">
                <tr>
                    <td>${ x.index }</td>
                    <td>${ x.count }</td>
                    <td>${ name }</td>
                    <td>${ x.first }</td>
                    <td>${ x.last }</td>
                    <td>${ x.current }</td>
                </tr>
            </c:forEach>
            </table>
        </c:if>
    </div>

    <div class="wrapper">
        <p class="title">迭代Set</p>
        <c:if test="${ not empty set }">
            <table>
                <tr>
                    <th>index</th>
                    <th>count</th>
                    <th>var</th>
                    <th>is first</th>
                    <th>is last</th>
                    <th>current</th>
                </tr>
                <c:forEach items="${ set }" var="name" varStatus="x">
                    <tr>
                        <td>${ x.index }</td>
                        <td>${ x.count }</td>
                        <td>${ name }</td>
                        <td>${ x.first }</td>
                        <td>${ x.last }</td>
                        <td>${ x.current }</td>
                    </tr>
                </c:forEach>
            </table>
        </c:if>
    </div>

    <div class="wrapper">
        <p class="title">迭代List</p>
        <c:if test="${ not empty list }">
            <table>
                <tr>
                    <th>index</th>
                    <th>count</th>
                    <th>var</th>
                    <th>is first</th>
                    <th>is last</th>
                    <th>current</th>
                </tr>
                <c:forEach items="${ list }" var="name" varStatus="x">
                    <tr>
                        <td>${ x.index }</td>
                        <td>${ x.count }</td>
                        <td>${ name }</td>
                        <td>${ x.first }</td>
                        <td>${ x.last }</td>
                        <td>${ x.current }</td>
                    </tr>
                </c:forEach>
            </table>
        </c:if>
    </div>

    <div class="wrapper">
        <p class="title">"迭代"Map</p>
        <c:if test="${ not empty map }">
            <table>
                <tr>
                    <th>index</th>
                    <th>count</th>
                    <th>var</th>
                    <th>is first</th>
                    <th>is last</th>
                    <th>current</th>
                </tr>
                <c:forEach items="${ map }" var="entry" varStatus="x">
                    <tr>
                        <td>${ x.index }</td>
                        <td>${ x.count }</td>
                        <td>
                            key: ${ entry.key }
                            /
                            value: ${ entry.value }
                        </td>
                        <td>${ x.first }</td>
                        <td>${ x.last }</td>
                        <td>${ x.current }</td>
                    </tr>
                </c:forEach>
            </table>
        </c:if>
    </div>

    <div class="wrapper">
        <p class="title">当作循环使用</p>
        <c:forEach var="i" begin="1" end="10" step="1">
            <span>${ i }</span>
        </c:forEach>
        <hr>
        <c:forEach var="i" begin="1" end="10" step="2">
            <span>${ i }</span>
        </c:forEach>
    </div>

</body>
</html>
